package com.zhanggm.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.zhanggm.user.entity.User;
import com.zhanggm.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.UsesSunHttpServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2024-05-22
 */
@RestController
@RequestMapping("/user")
public class UserController {



    @Autowired
    IUserService iUserService;

    @Value("${server.port}")
    private String serverPort;


    @GetMapping("getById")
    public User getById(@RequestParam("id") Integer id) {

        return iUserService.getById(id);
    }

    @GetMapping("user/getByUsername")
    public User getByUsername(@RequestParam("username") String username) {
        LambdaQueryWrapper<User> queryChainWrapper = new LambdaQueryWrapper<>();
        queryChainWrapper.eq(User::getUsername, username);
        User user = iUserService.getOne(queryChainWrapper);
        return user;
    }

}
